/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-11-30 上午09:23:17
 */
package com.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author zhaosj
 * 
 */
public class JsonTest {

	/**
	 * List
	 */
	public String listToJson() {
		boolean[] boolArray = new boolean[] { true, false, true };
		JSONArray jsonArray1 = JSONArray.fromObject(boolArray);
		System.out.println(jsonArray1);

		List list = new ArrayList();
		list.add("first");
		list.add("second");

		JSONArray jsonArray2 = JSONArray.fromObject(list);
		System.out.println(jsonArray2);

		JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']");
		System.out.println(jsonArray3);

		return null;
	}

	public String listToJsonObject() {

		JSONObject jo = new JSONObject();

		jo.put("null 01", null);
		jo.put("null 02", "" + null);

		return jo.toString();

	}

	/**
	 * Map
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String mapToJson() {
		Map map = new HashMap();
		map.put("name", "json1");
		map.put("bool", Boolean.TRUE);
		map.put("null 0001==================", null);
		map.put("null 02", "" + null);

		map.put("int", new Integer(1));
		map.put("arr", new String[] { "a", "b" });
		map.put("func", "function(i){ return this.arr[i]; }");

		List list = new ArrayList();

		list.add(map);

		// JSONObject json = JSONObject.fromObject(map);
		// System.out.println(json);

		JSONArray json2 = JSONArray.fromObject(list);

		return json2.toString();
	}

	public String testNullString() {
		JSONArray jsonArray = new JSONArray();

		return jsonArray.toString();
	}

	public static void main(String[] args) {
		JsonTest jt = new JsonTest();
		String str = jt.testNullString();

		System.out.println("-" + str + "-");

	}

}
